/**
 * @description  : 卷烟六面照
 * @descriptionDetail : 卷烟六面照
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-12-05 15:33:52
 */
<template>
  <view class="u-pages">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view>
      <u-card title="条图">
        <view slot="body">
          <view class="">
            <u-swiper
              :list="swStript"
              mode="dot"
              :title="true"
              height="484"
              indicator-pos="bottomCenter"
            ></u-swiper>
          </view>
        </view>
      </u-card>
      <u-card title="盒图">
        <view slot="body">
          <view class="">
            <u-swiper
              :list="boStript"
              mode="dot"
              :title="true"
              height="484"
              indicator-pos="bottomCenter"
            ></u-swiper>
          </view>
        </view>
      </u-card>
    </view>
  </view>
</template>

<script>
import {
  PATHROOT,
} from "@/common/path.config.js";
import zjCommonService from "@/service/common/common.service";
import queryService from "@/service/check/query.service"
// import fsection from "@/components/form-section.vue";
export default {
  components: {
    // fsection,
  },
  onLoad() {
    this.cigar = this.getRouteParam();
  },
  data() {
    return {
      cigar: {},
      user: this.$storage.get(this.$rp.common.USER),
      viewImgUrl: PATHROOT.BASE + "/commonfile/filestore/viewImgUrl.do",
      fileViewUrl: PATHROOT.BASE + "/commonfile/filestore/downloadFile.do",
      listImgs: [],
      picList: [],
      swStript: [], // 条图
      boStript: [], // 盒图
    }
  },
  mounted() {
    this.viewImgUrl += "?tk=" + this.user.tk + "&imgUrl=";
    this.fileViewUrl += "?tk=" + this.user.tk + "&fileId=";
    this.init();
  },
  methods: {
    init() {
      this.$modal.showLoading('加载中..');
      let self = this;
      zjCommonService.searchCigarImgs(this.cigar.productUuid).then(res => {
        if (res.success) {
          self.$modal.hideLoading();
          this.picList = res.bean.cigProductFile || [];
          let stripList = this.picList.filter(item => {
            if (item.pictureType == '01') return item
          })
          let boxList = this.picList.filter(item => {
            if (item.pictureType == '02') return item
          });
          let swTmpStript = [{
            image: stripList.length > 0 ? stripList[0].stripBack : '',
            title: "背面",
          }, {
            image: stripList.length > 0 ?  stripList[0].stripBehind : '',
            title: "后侧",
          }, {
            image: stripList.length > 0 ?  stripList[0].stripDirect : '',
            title: "正面",
          }, {
            image: stripList.length > 0 ?  stripList[0].stripFront : '',
            title: "前侧",
          }, {
            image: stripList.length > 0 ?  stripList[0].stripLeft : '',
            title: "左面",
          }, {
            image: stripList.length > 0 ?  stripList[0].stripRight : '',
            title: "右面",
          },];
          let boTmpStript = [{
            image:boxList.length > 0 ?  boxList[0].stripBack : '',
            title: "背面",
          }, {
            image:boxList.length > 0 ? boxList[0].stripBehind : '',
            title: "后侧",
          }, {
            image:boxList.length > 0 ? boxList[0].stripDirect : '',
            title: "正面",
          }, {
            image:boxList.length > 0 ? boxList[0].stripFront : '',
            title: "前侧",
          }, {
            image:boxList.length > 0 ? boxList[0].stripLeft : '',
            title: "左面",
          }, {
            image:boxList.length > 0 ? boxList[0].stripRight : '',
            title: "右面",
          },];
          Promise.all(swTmpStript.map(itm => {
            return this.getFile(itm.image);
          })).then(r => {
            this.swStript = [];
            for (let i = 0; i < r.length; i++) {
              this.swStript.push({
                image: r[i].gfiId ? queryService.previewImg(r[i].gfiId) : '../../../../static/check/nophoto.png',
                title: swTmpStript[i].title,
              });
            }
            console.log(this.swStript);
          }).catch(e => {
            console.log(e)
          });
          Promise.all(boTmpStript.map(itm => {
            return this.getFile(itm.image);
          })).then(r => {
            this.boStript = [];
            for (let i = 0; i < r.length; i++) {
              this.boStript.push({
                image: r[i].gfiId ? queryService.previewImg(r[i].gfiId) : '../../../../static/check/nophoto.png',
                title: swTmpStript[i].title,
              });
            }
            console.log(this.boStript);
          }).catch(e => {
            console.log(e)
          });
        } else {
          self.$modal.hideLoading();
          console.log(res.msg)
        }
      }).catch(err => {
        self.$modal.hideLoading();
        console.log(err)
      });
    },
    getFile(id) {
      return new Promise((resolve, reject) => {
        if(this.$u.test.isEmpty(id)) {
          resolve({})
          return;
        }
        zjCommonService.goFiles(id, "").then(res => {
          if (res.success && res.data.length > 0) {
            resolve(res.data[0]);
          } else {
            resolve({});
          }
        }).catch(e => {
          console.log('id=' + id + '----图片获取失败');
          resolve({});
        });
      });
    },
  },
}
</script>

<style scoped lang="scss">
	.card-p {
		background-color: white;

	}

	.u-pages {
		background-color: #f3f4f6;
		height: 100%;
	}

	/deep/.u-swiper-title {
		text-align: center;
	}
</style>
